package com.gopay.common.cps.dao.wallet.bouns.impl;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.cps.dao.wallet.bouns.WaBounsMainOrderDao;
import com.gopay.common.domain.dps.WaBounsMainOrder;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 
 * @author boai 
 * on 2017/1/5.
 */
@Repository("waBounsMainOrderDao")
public class WaBounsMainOrderDaoImpl extends BaseDAOImpl<WaBounsMainOrder, Integer> implements WaBounsMainOrderDao {

	/**
	 * 
	 * 根据国付宝订单号查询红包业务主表，当查询结果唯一时，返回结果，否则返回空。
	 * @param gopayOrderId
	 * @return WaBounsMainOrder
	 * add by tangyang at 20170106
	 */
	@Override
	public WaBounsMainOrder queryByGopayOrderId(String gopayOrderId) {
		// TODO Auto-generated method stub
		String hql = " select m from WaBounsMainOrder m where m.gopayOrderId = :gopayOrderId";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("gopayOrderId", gopayOrderId);
		List<WaBounsMainOrder> waBounsMainOrderList = findByHql(hql ,params);
		if(waBounsMainOrderList!=null && waBounsMainOrderList.size()==1){
			return waBounsMainOrderList.get(0);
		}
		return null;
	}

	@Override
	public List<WaBounsMainOrder> findbyPassword(String password) {
		StringBuffer sb=new StringBuffer();
		sb.append("  from WaBounsMainOrder r");
		sb.append(" where r.bounsWord = '");
		sb.append(password+"' ");
		sb.append(" and r.wordStatus<>30 ");
		List<WaBounsMainOrder> waBounsMainOrderList=findByHql(sb.toString());
		return waBounsMainOrderList;
	}

	@Override
	public List<WaBounsMainOrder> findbyAblePassword(String password) {
		StringBuffer sb=new StringBuffer();
		sb.append("  from WaBounsMainOrder r");
		sb.append(" where r.bounsWord = '");
		sb.append(password+"' ");
		sb.append(" and r.wordStatus = 20 ");
		List<WaBounsMainOrder> waBounsMainOrderList=findByHql(sb.toString());
		return waBounsMainOrderList;
	}
}
